﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DAL;

public partial class Form_ThongTinTaiKhoanNganHang : System.Web.UI.Page
{
    GetData getData;
    protected void Page_Load(object sender, EventArgs e)
    {
        Session["MaKh"] = "17";
    }

    public GioHang TaoMoiGioHang()
    {
        int maKH = (int)int.Parse(Session["MaKh"].ToString());
        getData = new GetData();
        GioHang gh = new GioHang();
        gh.DiaChiGiaoHang = txtDiaChiGiaoHang.Text;
        gh.TenNguoiNhanHang = txtTenNguoiMuaHang.Text;
        gh.NgayGiao = (DateTime)DateTime.Parse(txtNgayGioHang.Text);
        gh.NgayTao = DateTime.Now;
        gh.NhanVienGiaoHang = "Tran Ngoc Thuan";
        gh.NhanVienXacNhan = "Tran Ngoc Thuan";
        gh.MaKH = maKH;
        getData.TaoMoiGioHang(gh);
        if (gh != null)
        {
            ChiTietGioHang chiTietGioHang = new ChiTietGioHang();
            List<NewCart> listNewCart = (List<NewCart>)Session["Cart"];
            if (listNewCart.Count > 0)
            {
                foreach (NewCart nc in listNewCart)
                {
                    chiTietGioHang.MaGioHang = gh.MaGioHang;
                    chiTietGioHang.MaSP = nc.MaSp;
                    chiTietGioHang.SoLuong = nc.SoLuong;
                    chiTietGioHang.DonGia = nc.Gia;
                    getData.TaoMoiChiTietGioHang(chiTietGioHang);
                }
            }
        }
        return gh;
    }

    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        GioHang gh = new GioHang();
        gh = TaoMoiGioHang();
        if (gh != null)
        {
            Response.Redirect("ThankYou.aspx");
        }
    }
}